<template>
        <div class="k-progress"  @touchmove="proTouchMove($event)">

            <div class="k-progress-runway"></div>
            <div class="k-progress-progress" :style="{width:present+'%'}">
                <div class="k-progress-cbox">
                  <!-- 圆点 -->
                    <div class="k-progress-control"  @touchstart="proTouchStart($event)" @touchend="proTouchEnd($event)"></div>
                </div>
            </div>
        </div>

</template>

<script>
export default {
  props: ["present"],
  data() {
    return {
      touchFlag: false
    };
  },
  methods: {
    proTouchStart(event) {
      this.touchFlag = true;
    },
    proTouchMove(e) {
      if (this.touchFlag) {
        //进度条位置
        let ppx = e.currentTarget.offsetLeft;
        let ppw = e.currentTarget.offsetWidth;
        //拖动到的位置
        let cpx = e.changedTouches[0].pageX;
        
        let present = (cpx - ppx) / ppw;
        if(present>0.99){
          present = 0.99;
        }
		    this.$emit("progressChange",present)
        
      }
    },
    proTouchEnd(event) {
      this.touchFlag = false;
    }
  }
};
</script>


<style lang="scss">
.k-progress {
  width: 100%;
  height: 30px;
  position: relative;
  .k-progress-runway {
    background-color: darkgray;
    width: 100%;
    height: 4px;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
  }
  .k-progress-progress {
    background-color: #42b983;
    width: 0;
    height: 4px;

    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
  }
  .k-progress-cbox {
    position: relative;
    height: 100%;
  }
  .k-progress-control {
    width: 16px;
    height: 16px;
    background-color: #42b983;
    border: 4px solid #fff; 
    border-radius: 50%;
    box-sizing: border-box;
    position: absolute;
    top: 50%;
    transform: translateX(50%) translateY(-50%);
    right: 0;
  }
}
</style>
